package light.head.dao.oa;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import light.head.constant.Parm;
import light.head.enm.RESULT;
import light.head.framework.base.BaseDAO;
import light.head.framework.entity.PageBean;
import light.head.model.Photo;

@Service
public class PhotoDAO extends BaseDAO<Photo, Integer> {
	

	public RESULT findByMap(Map<String, String> map, PageBean pb){
		StringBuffer hql = new StringBuffer("FROM Photo p WHERE 1=1");

		List<Object> list = null;
		String alc = map.get(Parm.CODE);
		if (null != map) {
			list = new ArrayList<Object>();
			if(isNotNull(alc)) {
				hql.append(" AND p.alc = ?");
				list.add(Integer.parseInt(alc));
			}
			
		}
		hql.append(" AND p.deleted = 0 or p.deleted is null ");
		hql.append(" ORDER BY p.code DESC");
		
		if (findToPageBean(hql.toString(), pb, list) == RESULT.SUCCESS)
			return RESULT.SUCCESS;
		
		return RESULT.ERROR;
	}
	
	public List<Photo> findByAlc(Integer alc) {
		StringBuffer sql = new StringBuffer("FROM Photo p WHERE p.alc = ? AND p.deleted = 0 or p.deleted is null");
		
		return find(sql.toString(),alc);
	}
}
